/*
	File: E:/3D/games/mgt/panzer_2010/data/scripts/simple_camera.nut
	Author: Francois Gutherz
*/

/*!
	@short	SimpleCamera
	@author	Francois Gutherz
*/
class	SimpleCamera
{
	/*!
		@short	OnUpdate
		Called during the scene update, each frame.
	*/

	item_tank			=	0
	scene				=	0
	dist_camera_to_tank	=	0
	cam_pos				=	0

	function	OnUpdate(item)
	{
		local	_pos
		_pos = ItemGetPosition(item_tank) + ItemGetLinearVelocity(item_tank) + dist_camera_to_tank
		cam_pos = cam_pos.Lerp(0.975, _pos)
		ItemSetPosition(item, cam_pos)
	}

	/*!
		@short	OnSetupDone
		Called when the item is about to be setup.
	*/
	function	OnSetupDone(item)
	{
		scene =	ItemGetScene(item)
		item_tank = SceneFindItem(scene, "tank")
		print("SimpleCamera::OnSetupDone() : found item '" + ItemGetName(item_tank) + "'.")

		cam_pos = ItemGetPosition(item)
		dist_camera_to_tank = Vector(-5,15,-15) //cam_pos - ItemGetPosition(item_tank)
		dist_camera_to_tank = (dist_camera_to_tank.Normalize()).Scale(20.0)
		ItemSetPosition(item, ItemGetPosition(item_tank) + dist_camera_to_tank)
		CameraSetFov(ItemCastToCamera(item), DegreeToRadian(45.0))

		SceneSetCurrentCamera(scene, ItemCastToCamera(item))
	}
}
